package BackgammonBot;


public class runBackgammonBot 
{

	private final static boolean DEBUG = false;
	
	public static void main(String[] args) 
	{
		int runTimeInMilliSeconds;
		String InputFilePath;
		String OutputFilePath;
		
		
		if (DEBUG) 
		{
			InputFilePath = System.getProperty("user.dir") + "/Session4/currentBoard.txt";
			OutputFilePath= System.getProperty("user.dir") + "/Session4/outputBoard.txt";
			runTimeInMilliSeconds = 3000;			
		} 
		else 
		{
			if (args.length != 6) 
			{
		        System.out.println("Missing arguments!");
		        System.out.println("Must be like: <relative_path_to_bot_executable_including_everything> -i <relative_path_to_input_file> -o <relative_path_to_output_file> -t <milleseconds>");
		        System.out.println("e.g.: java -jar ./superbot/botty.jar -o ./results/round10/g1vsG2/i0.txt -i ./results/round10/g1vsG2/o1 -t 3000");
		        return;
			}
			
			InputFilePath = null;
			OutputFilePath = null;
			runTimeInMilliSeconds = -1;
			
			// read args
			for (int i = 0; i < args.length; i++) 
			{
				switch (args[i].trim()) 
				{
					case "-i":
						if(args[i+1] != null)
							InputFilePath = args[i+1].trim();
						else 
						{
							System.out.println("-i argument missing.");
						}
						break;
					case "-o":
						if(args[i+1] != null)
							OutputFilePath = args[i+1].trim();
						else 
						{
							System.out.println("-o argument missing.");
						}
						break;
					case "-t":
						if(args[i+1] != null) 
						{
							runTimeInMilliSeconds = Integer.parseInt(args[i+1].trim());
							if (runTimeInMilliSeconds <=0) 
							{
								System.out.println("-t argument must be >0!");
								return;
							}
						} 
						else 
						{
							System.out.println("-t argument missing.");
						}
						break;				
					default:
						break;
				}
			}
			
			if(InputFilePath == null || OutputFilePath == null)
			{
				System.out.println("Missing arguments!");
				return;
			}
		}
		Bot myBot = new Bot(runTimeInMilliSeconds, InputFilePath, OutputFilePath);
		System.out.println(myBot.getRemainingTime());

	}

}